// pages/theatre/theatre.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    word:'123321',
    theatreList:[],
    cityname:'',
  },
  tapTheatreItem(e){
    let {i} =e.currentTarget.dataset
    let t = this.data.theatreList[i]
    console.log(t)
    wx.openLocation({
      latitude: t.location.lat,
      longitude: t.location.lng,
    })
  },
  
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var qqmapsdk = getApp().globalData.qqmapsdk
    qqmapsdk.search({
      keyword:'影院',
      page_size:20,
      success:(res)=>{
        wx.showLoading({
          title: '加载中',
        })
        let theatreList = res.data.map(v=>{
          return{
            ...v,
            km:(v._distance/1000).toFixed(2)
          }
        })
        console.log(theatreList)
        this.setData({
          theatreList:theatreList
        })
        wx.hideLoading()
      }
    })

  },

  onShow(){
    this.setData({
      cityname:getApp().globalData.selectedCity
    })
  },
  tapSearch(){
    var qqmapsdk = getApp().globalData.qqmapsdk
    qqmapsdk.search({
      keyword:'影院'+this.data.word,
      region:this.data.cityname,
      page_size:20,
      success:(res)=>{
        wx.showLoading({
          title: '加载中',
        })
        let theatreList = res.data.map(v=>{
          return{
            ...v,
            km:(v._distance/1000).toFixed(2)
          }
        })
        console.log(theatreList)
        this.setData({
          theatreList:theatreList
        })
        wx.hideLoading()
      }
    })
  }
})